moveStroe.controller('categoryCtr',function($scope,myAlert,tree,alertContent){
  $scope.myData=[];
  var gets=function(){
    $.get( '/Admin/Category/gets',function( data ){
      $scope.myData=tree.conv(data.msg);
      $scope.$apply();//需要手动刷新
    })
  }
  gets();

  var del=function(id){
    $.get('/Admin/Category/id',{id:id},function(data){
      console.log(data);
      if(data.status){
        myAlert(data.msg);
      }else{
        myAlert(data.msg);
      }
    })
  }
  var get=function(id){
    $.get('/Admin/Category/get',{id:id},function(data){
      if(data.status){
        alertContent.open(data.msg,'lg');
      }else{
        myAlert.open(data.msg);
      }
    })
  }
  $scope.get=get;

  //删除数据
  $scope.del = function($id){
    $.get( '/Admin/Category/del', { id: $id }, function( data ){
      if( data.status ){
        myAlert.open( data.msg );
        gets();
      }else{
        myAlert.open( data.msg );
      }
    } )
  }

});

moveStroe.controller('addCtr',function($scope,$state,myAlert,tree){
  $scope.categorys=[];
$scope.selected=1;
  $scope.froms={
    pid:'0',
    name:'',
    intro:'',
    status:true,
  };
  var getCategory=function(){
    $.get( '/Admin/Category/gets',  function( data ){
      var ret= data.msg.data
      var ret=tree.conv(data.msg)
      for(b in ret){
        ret[b].tree1='';
        for( var i=1;i<ret[b].tree;i++){
          ret[b].tree1+='++';
        }
      }
      $scope.categorys=ret;
      $scope.$apply();//需要手动刷新
    } )
  }
  getCategory();

  var add=function(){
    $.post( '/Admin/Category/save',$scope.froms,function( data ){
      if(data.status){
        myAlert.open(data.msg);
        $state.go('index.class');
      }else{
        myAlert.open(data.msg);
      }
    })
  }

  $scope.formsButton=function(){
     add();
  }

});

moveStroe.controller('editCtr',function($scope,$state,myAlert,$stateParams,tree){

  var id=$stateParams.id;

  if(id==''||id==undefined){
    $state.go('index.class')
  }
  $scope.categorys=[{
    tree:1,
    data:{
      id:'0',
      name:'顶级',
    }
  }];
  $scope.selected=1;
  $scope.froms={
    id:'',
    pid:0,
    name:'',
    intro:'',
    status:true,
  };
  var getCategory=function(){
    $.get( '/Admin/Category/gets',  function( data ){
      var ret= data.msg.data
      var ret=tree.conv(data.msg)
      for(b in ret){
        ret[b].tree1='';
        for( var i=0;i<ret[b].tree;i++){
          ret[b].tree1+='++';
        }
      }
      $scope.categorys=ret;
      $scope.$apply();//需要手动刷新
    } )
  }
  getCategory();

  var get=function(id){
    $.get( '/Admin/Category/get',{id:id},function( data ){
      data.msg.status=data.msg.status==1?true:false;
      $scope.froms= data.msg;
      $scope.$apply();//需要手动刷新
    } )
  }
  get(id);

  var add=function(){
    $.post( '/Admin/Category/update',$scope.froms,function( data ){
      if(data.status){
        myAlert.open(data.msg);
        $state.go('index.class');
      }else{
        myAlert.open(data.msg);
      }
    })
  }

  $scope.formsButton=function(){
    console.log( $scope.froms)
    $scope.froms.status= $scope.froms.status==true?1:0;
    add();
  }

});


